<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="hibernatelogic.HibRoles"%>
<%@page import="orm.Roles"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%
	HttpSession sess = request.getSession();
	
	if (sess.isNew()) {
		response.sendRedirect("/my-pet-project-0/Login.jsp");
	} else {
%>
<%
	if (((String) sess.getAttribute("UserRole")).equals("3")) {
%>
<%
			HibRoles hibRoles = new HibRoles();
			Collection col = null;
			Iterator it = null;
			col = hibRoles.getAllRoles();
			ArrayList convList = (ArrayList) col;
			it = convList.iterator();
			Roles tmpRole = new Roles();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add users</title>
</head>
<body>
	<a href="/my-pet-project-0/Login.jsp">Logout</a>
	<a href="/my-pet-project-0/AdminStartPage.jsp">Back</a>
	<br>
	<br>
	<center>Fill the form to create an user</center>
	<br>
	<center>
		
		<form action="add-user-servlet" method="post" name="addform">
			NEW USERNAME: <br> <input type="text" name="nname" maxlength="30"> <br>
			LOGIN: <br> <input type="text" name="nlogin" maxlength="20"> <br>
			PASSWORD: <br> <input type="text" name="npassword" maxlength="20"> <br>
			ROLE: <select name="nrole">
				<%
					while (it.hasNext()) {
				%>
				<%
					tmpRole = (Roles) it.next();
				%>
				<option value=<%=tmpRole.getRole_id()%>><%=tmpRole.getRole_name()%>
					<%
						}
					%>
				
			</select> <br> <input type="submit" value="Add user" onclick="return CheckFields()">
		</form>
		
	</center>
	
	<script language ="javascript" type="text/javascript">
		function CheckFields(){
			if(document.forms.addform.nname.value !=""){
				
			} else {
				alert("Please, enter a USERNAME");
				document.forms.addform.nname.focus();
				return false;
			}
			if(document.forms.addform.nlogin.value !=""){
				
			} else {
				alert("Please, enter new LOGIN");
				document.forms.addform.nlogin.focus();
				return false;
			}
			if(document.forms.addform.npassword.value !=""){
				
			} else {
				alert("Please, enter new PASSWORD");
				document.forms.addform.npassword.focus();
				return false;
			}
		}
	</script>
	
</body>
</html>
<%
	} else {
%>
<%
	response.sendError(response.SC_FORBIDDEN,
					"Not permitted to enter as ADMINISTRATOR");
%>
<%
	}
	}
%>